<template lang="pug">
.record
  .header
    .header-search
      el-select(placeholder="选择操作类型" prefix-icon="el-icon-search" clearable v-model="type" @change="search")
        el-option(v-for="item in typeOptions", :key="item.value", :label="item.label", :value="item.value")
      el-input(placeholder="材料名称/发布者" prefix-icon="el-icon-search" v-model="createBy" @change="search")
  .record-table
    .record-table-header {{sampleName}}
    el-table(
      height="calc(100% - 51px)"
      :data="list"
      :header-cell-style="{ fontSize: '14px', color: '#64698F', background: '#F8F7FC' }"
      border
      style="width: 100%"
      v-loading="loading"
      empty-text="未找到符合条件的内容"
    )
      el-table-column(align="center" width="60" label="序号" prop="sampleLogsId")
      el-table-column(align="center" label="操作类型" prop="type")
        template(slot-scope="scope") {{scope.row.type | filterSampleType}}
      el-table-column(align="center" label="操作内容" prop="content")
      el-table-column(align="center" label="操作者" prop="createByName")
      el-table-column(align="center" label="操作时间" prop="createTime")
  .table-pagination
    el-pagination(
      background
      layout="prev, pager, next, jumper"
      :total="total"
      :current-page="currentPage"
      :page-size="pageLines"
      @current-change="currentChange"
    )
</template>

<script>
import { getSampleLogList } from 'api'
export default {
  name: 'sampleRecord',
  data () {
    return {
      loading: false,
      currentPage: 1,
      pageLines: 20,
      total: 0,
      typeOptions: [
        { label: '设置上下架', value: 1 },
        { label: '设置新品', value: 2 },
        { label: '设置推荐', value: 3 },
        { label: '入库操作', value: 4 },
        { label: '出库操作', value: 5 },
        { label: '货架号修改', value: 6 }
      ],
      type: '',
      createBy: '',
      sampleName: '',
      list: []
    }
  },
  methods: {
    search () {
      this.currentPage = 1
      this.getList()
    },
    currentChange (page) {
      this.page = page
      this.getList()
    },
    async getList () {
      try {
        let query = {
          currentPage: this.currentPage,
          pageLines: this.pageLines,
          sampleId: this.$route.params.id
        }
        if (this.type) query.type = this.type
        if (this.createBy) query.createBy = this.createBy
        const { ResultSet } = await this.$axios.post(getSampleLogList, { ...query })
        this.list = ResultSet.userData.sampleLogList
        this.total = ResultSet.recordNumber
      } catch (err) {
        this.$message.error(err.message || err.ResultSet.errors)
      }
    }
  },
  beforeRouteEnter (to, from, next) {
    next(vm => {
      vm.sampleName = to.query.sampleName
      vm.getList()
    })
  }
}
</script>

<style lang="scss" scoped>
.record {
  width: 100%;
  height: 100%;
  background: #FFFFFF;
  border: 1px solid #F3F3F4;
  box-sizing: border-box;
  box-shadow: 0px 4px 0px #F3F3F4;
  border-radius: 10px;
  padding: 0 40px;
}
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  .el-input {
    width: 202px;
    margin-right: 16px;
  }
  .el-select {
    margin-right: 16px;
  }
  .el-cascader {
    margin-right: 16px;
  }
  .header-search {
    display: flex;
    align-items: center;
  }
  .header-info {
    font-size: 14px;
    line-height: 22px;
    color: #8B8EAB;
  }
}
.record-table {
  height: calc(100% - 150px);
}
.table-pagination {
  padding: 24px 0;
  text-align: right;
}
.record-table-header {
  height: 52px;
  padding: 15px 0;
  font-size: 16px;
  font-weight: bold;
}
</style>